<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小红书瀑布流</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            padding: 10px;
        }

        .waterfall-container {
            column-count: 2; /* 两列 */
            column-gap: 10px; /* 列间距 */
        }

        @media (min-width: 768px) {
            .waterfall-container {
                column-count: 3; /* 三列 */
            }
        }

        @media (min-width: 1024px) {
            .waterfall-container {
                column-count: 4; /* 四列 */
            }
        }

        .item {
            break-inside: avoid; /* 防止元素被分割到两列 */
            margin-bottom: 10px;
            background-color: #fff;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        .item img {
            width: 100%;
            display: block;
        }
    </style>
</head>
<body>
    <div class="waterfall-container" id="waterfall">
        <!-- 动态生成的图片将插入到这里 -->
    </div>

    <script>
        // 模拟图片数据，图片的高度不固定
        const data = [
            '../1.png',
            '../2.png',
            '../2.png',
            '../1.png',
            '../2.png',
            '../1.png',
            '../1.png',
            '../2.png',
            '../1.png',
            '../2.png',
        ];

        const waterfallContainer = document.getElementById('waterfall');

        // 动态生成图片并插入到瀑布流容器中
        function renderWaterfall(images) {
            images.forEach(src => {
                const div = document.createElement('div');
                div.classList.add('item');
                div.innerHTML = `<img src="${src}" alt="Image">`;
                waterfallContainer.appendChild(div);
            });
        }

        // 初次渲染
        renderWaterfall(data);
    </script>
</body>
</html>
